package edu.gdkm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import edu.gdkm.dao.UserMapper;
import edu.gdkm.entity.PageResult;
import edu.gdkm.pojo.User;
import edu.gdkm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User login(User user) {
        return userMapper.login(user);
    }
    @Override
    public Integer addUser(User user){
        return  userMapper.addUser(user);
    }
    @Override
    public Integer delUser(int id){
        return  userMapper.delUser(id);
    }
    @Override
    public Integer editUser(User user) {
        return userMapper.editUser(user);
    }
    @Override
    public PageResult search(User user, Integer pageNum, Integer pageSize) {
        // 设置分页查询的参数，开始分页
        PageHelper.startPage(pageNum, pageSize);
        Page<User> page=userMapper.searchUsers(user);
        return new PageResult(page.getTotal(),page.getResult());
    }
    @Override
    public User findById(int id) {
        return userMapper.findById(id);
    }
    @Override
    public Integer checkName(String name){
        return  userMapper.checkName(name);
    }
    @Override
    public Integer checkEmail(String email){
        return  userMapper.checkEmail(email);
    }
}
